<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/12/6
 * Time: 9:51 PM
 */

namespace app\model;


class Bill extends Base
{
    protected $pk = 'id';
    // 此处表名请务必设置为public
    public $table = 'bill';

    /**
     * @purpose 绑定用户模型
     * @return \think\model\relation\HasOne
     */
    public function member ()
    {
        return $this->hasOne('Member', 'uid', 'uid');
    }
    /**
     * @purpose 创建账单
     * @param $uid
     * @param $type
     * @param $order_no
     * @param $quota
     * @param $pay_method
     * @param $desc
     */
    public static function addToBill(
        $uid,
        $type,
        $order_no,
        $quota,
        $pay_method,
        $desc
    )
    {
        $data                 = [];
        $data['uid']          = $uid;
        $data['type']         = $type;
        $data['order_no']     = $order_no;
        $data['quota']        = $quota;
        $data['pay_method']   = $pay_method;
        $data['descriptions'] = $desc;
        return self::M()
            ->data($data)
            ->save();
    }

}